#include "input.h"

InputState::InputState()
{
    _x = 0, _y = 0, _wheel = 0;
    _left = false, _right = false;
}

int InputState::getMouseX() const
{
    return _x;
}

int InputState::getMouseY() const
{
    return _y;
}

bool InputState::leftPressed() const
{
    return _left;
}

bool InputState::rightPressed() const
{
    return _right;
}

int InputState::getWheel() const
{
    return _wheel;
}

InputState& InputState::operator=(const InputState& rhs)
{
    if (this == &rhs) {
        return *this;
    }

    _x = rhs._x;
    _y = rhs._y;
    _wheel = rhs._wheel;
    _left = rhs._left;
    _right = rhs._right;

    return *this;
}



const InputState& Input::getCurrent() const
{
    return _curState;
}

const InputState& Input::getPrevious() const
{
    return _prevState;
}

const InputState& Input::getDiff() const
{
    return _diffState;
}

void Input::update()
{
    int x, y, wheel;
    bool left, right;
    int wndW, wndH;

    glfwGetWindowSize(&wndW, &wndH);

    glfwGetMousePos(&x, &y);
    wheel = glfwGetMouseWheel();

    if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) {
        left = true;
    } else {
        left = false;
    }
    if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS) {
        right = true;
    } else {
        right = false;
    }

    _prevState = _curState;

    _curState._x = x;
    _curState._y = wndH - y;
    _curState._wheel = wheel;
    _curState._left = left;
    _curState._right = right;

    _diffState._x = _curState._x - _prevState._x;
    _diffState._y = _curState._y - _prevState._y;
    _diffState._wheel = _curState._wheel - _prevState._wheel;
    _diffState._left = false;
    _diffState._right = true;
}
